function err = calErr(nos, model, R, lambda) 
% calculate the error
Sigma = model.Sigma;
U = model.U;
V = model.V;

[p,m] = size(nos);
n = p*m;

W = sqrt(sum(R./(2*pi*(repmat(Sigma(:)',n,1))),2));
W = reshape(W, p, m);
err = norm(W.*(nos - U*V'), 'fro')^2 + lambda/2*(norm( U, 'fro')^2 + norm(V, 'fro')^2);